using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Options_AddRecurrenceTypes : System.Web.UI.Page
{
    DataSet ds = new DataSet();
    private string userID;
    protected void Page_Load(object sender, EventArgs e)
    {
        userID = Session["UserID"].ToString();

        ds = workLayerWeb.GetRecurrenceTypes(userID);

        GridView1.DataSource = ds;
        GridView1.DataBind();

        for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
        {
            if (i < GridView1.Rows.Count)
            {
                GridView1.Rows[i].ID = ds.Tables[0].Rows[i].ItemArray[ds.Tables[0].Columns.Count - 1].ToString();
            }
        }
    }

    private void FillRecurrenceTypes(string userID)
    {
        DataSet ds = workLayerWeb.GetRecurrenceTypes(userID);
        GridView1.DataSource = ds;
        GridView1.DataBind();


    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        bool typeSelected = false;
        int i;

        for (i = 0; i < rblRecurrenceUnit.Items.Count; i++)
        {

            if (rblRecurrenceUnit.Items[i].Selected)
            {
                typeSelected = true;
                break;
            }
        }

        if (typeSelected && txtPeriod.Text != "")
        {
            //RecurrenceTypes recType = new RecurrenceTypes(rblRecurrenceUnit.Items[i].Text, txtPeriod.Text);
            ds = workLayerWeb.AddRecurrenceType(rblRecurrenceUnit.Items[i].Text, txtPeriod.Text, userID);

            FillRecurrenceTypes(userID);
 
        }
    }

    protected void btnCancel_Click(object sender, EventArgs e)
    {
        Response.Redirect("GeneralCalendar.aspx");
    }
    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        string reccurenceTypeID = GridView1.Rows[e.RowIndex].ID;

        if (workLayerWeb.DeleteRecurrenceType(reccurenceTypeID, Session["UserID"].ToString()))
        {
            this.Page_Load(sender, e);
        }
    }
}
